import 'package:xvideos/extension/string_check.dart';
import 'package:xvideos/hj_model/comment/reply_model.dart';

class CommentModel {
  String? id;
  String? cid; //只在消息评论中用
  String? objID;
  int? userID;
  String? userName;
  String? userPortrait;
  String? content;

  bool? isFirstComment;

  int? likeCount;
  int? commCount;
  bool? isAuthor;
  bool? isLike;
  bool? isFollow;
  bool? isDelete;
  String? gender;
  int? status;
  String? city;
  String? createdAt;
  bool? isStep;
  // String? link;
  String? vipName;
  List<int>? awards;
  String? searchKeyword;
  int? linkType;
  String? linkStr;
  bool get hasMuchReply {
    // 有多个回复内容
    return (info?.length ?? 0) > 1;
  }

  bool? haveMoreData = false; // true有子评论
  bool isReplyPackUp = false; // 收起回复
  int? replyPageIndex = 1;
  List<ReplyModel>? info;
  double? grade; //评论等级
  int? age;
  int? level;
  bool? isRequestReply = false; //是否正在请求更多回复中
  bool? isGodComment;
  int? code; // 错误code
  String? tip; // 错误提示
  int? step;
  int? vipLevel;
  bool? official; // 官方评论
  String? subObjName; //评论对象子集名称，
  String? subObjID; //评论对象子集id
  bool? superUser;
  String? image;
  bool get isOfficial {
    if (official == null) return false;
    return official!;
  }

  //true 隐藏 false 显示
  bool get isHideLikeOrComment {
    return ((linkType == 1 || linkType == 2) && linkStr?.isNotEmpty == true && searchKeyword?.isNotEmpty == true);
  }
  // CommentLink? linkItem; // 超链接评论，手动赋值
  // bool get isLinkStyle {
  //   return linkItem != null;
  // }

  bool get isCarNoComment {
    final content_ = content ?? '';
    return content_.containsCarno();
  }

  ///显示评论状态
  String get contentStatus {
    if (isDelete == true) {
      return "已删除";
    }
    if (status == 3) {
      return "已屏蔽";
    } else if (status == 2) {
      return "正在审核";
    } else {
      return content ?? "";
    }
  }

  String get showVipLevelIcon {
    final vipl = vipLevel ?? 0;
    if (vipl == 0) return '';
    if (vipl == 3) return 'assets/images/nut/super_vip.png';
    return 'assets/images/nut/user_vip_small.png';
  }

  static CommentModel fromJson(Map<String, dynamic>? map) {
    map ??= {};
    CommentModel info = CommentModel();

    info.image = map['image'];
    info.searchKeyword = map['searchKeyword'];
    info.linkStr = map['linkStr'];
    info.linkType = map['linkType'];
    info.official = map['isOfficial'];
    info.isStep = map['isStep'];
    info.id = map['id'];
    info.code = map["code"];
    info.tip = map["tip"];
    info.cid = map['cid'];
    info.objID = map['objID'];
    info.userID = map['userID'];
    info.userName = map['userName'];
    info.userPortrait = map['userPortrait'];
    info.content = map['content'];
    info.likeCount = map['likeCount'];
    info.commCount = map['commCount'];
    info.isAuthor = map['isAuthor'];
    info.isLike = map['isLike'];
    info.vipName = map['vipName'];
    info.isFirstComment = map['isFirstComment'];
    info.isFollow = map['isFollow'];
    info.isDelete = map['isDelete'];
    info.gender = map['gender']?.toString();
    info.status = map['status'];
    info.city = map['city'];
    info.createdAt = map['createdAt'];
    info.age = map['age'];
    info.level = map['level'];
    info.awards = (map['awards'] as List?)?.map((e) => int.tryParse(e.toString()) ?? 0).toList();
    info.superUser = map['superUser'];
    info.isGodComment = map['isGodComment'];
    info.info = (map['Info'] as List?)?.map((o) => ReplyModel.fromJson(o)).toList();

    if (map['grade'] != null) {
      info.grade = double.tryParse(map['grade'].toString());
    }
    info.step = map['step'];
    info.vipLevel = map['vipLevel'];
    info.subObjID = map['subObjID'];
    info.subObjName = map['subObjName'];
    return info;
  }

  Map toJson() => {
        'image': image,
        "id": id,
        "cid": cid,
        "objID": objID,
        "userID": userID,
        "userName": userName,
        "userPortrait": userPortrait,
        "content": content,
        "likeCount": likeCount,
        "commCount": commCount,
        "isAuthor": isAuthor,
        "isLike": isLike,
        "isFollow": isFollow,
        "isDelete": isDelete,
        "gender": gender,
        "status": status,
        "city": city,
        "createdAt": createdAt,
        "Info": info,
        "level": level,
        "age": age,
        'isGodComment': isGodComment,
        'isOfficial': isOfficial,
      };
}
